import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import cookie from 'react-cookie'
import cn from 'classnames'

import NavBar from '../components/NavBar'
import SideBar from '../components/SideBar'
import FooterBar from '../components/FooterBar'
import Breadcrumb from '../components/Breadcrumb'

import { userUpdata } from '../actions/user'
import { updataSystem } from '../actions/common'

class App extends Component {
  constructor(props) {
    super(props);
    if(__dev__){
      cookie.save('JSESSIONID', 'AA84A6A3875058A1856EC55BD3922621', { path: '/' });
    }
  }

  componentDidMount(){
    this.props.updataSystem(this.props.common&&this.props.common.user);
  }

  render() {
    return (
      <div className={cn("ant-layout-topaside",{'full-page': !this.props.sideBarShow})}>
        <NavBar />
        <aside className="ant-layout-sider">
          <SideBar location={this.props.location} />
        </aside>
        <div className="ant-layout-content">
          <Breadcrumb location={this.props.location}></Breadcrumb>
          <div className="content-inner">
            { this.props.children }
          </div>
        </div>
          {/*<FooterBar/>*/}
      </div>
    )
  }
}

function mapStateToProps(state) {
  return {
    sideBarShow: state.sideBar.show,
    common: state.common
  }
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators({ userUpdata, updataSystem }, dispatch)
}

export default connect(mapStateToProps, mapDispatchToProps)(App)